package Enum;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;

/*2014-8-8
 * 使用Enum來去避免寫"XXX"字串寫法在程式裡，只要去改Enum就可以了
 * 
 *2014-8-11
 * 修正可取出enum資料
 */

enum drink {
	BlackTea(0), MilkTea(1), PearlMilkTea(2);
	private int index;
	drink(int idx) {
		this.index = idx;
	}
	public int getIndex() {
		return index;
	}
	
	//亂數選擇一杯飲料
	private static final List<drink> VALUES = Collections
			.unmodifiableList(Arrays.asList(values()));
	private static final int SIZE = VALUES.size();
	private static final Random RANDOM = new Random();

	public static String randomDrink() {
		String drinkName=VALUES.get(RANDOM.nextInt(SIZE)).toString();
		return drinkName;
	}
}

// 去指定類型
enum iceOrSugar {
	full(0), half(1), no(2);
	private int index;

	iceOrSugar(int idx) {
		this.index = idx;
	}

	public int getIndex() {
		return index;
	}

	//亂數產生選擇，全糖、半糖、去糖的類型
	private static final List<iceOrSugar> VALUES = Collections
			.unmodifiableList(Arrays.asList(values()));
	private static final int SIZE = VALUES.size();
	private static final Random RANDOM = new Random();

	public static String randomIceOrSugar() {
		return VALUES.get(RANDOM.nextInt(SIZE)).toString();
	}
	public static iceOrSugar randomIceOrSugarTwo() {
		return VALUES.get(RANDOM.nextInt(SIZE));
	}
}


public class EnumTest {
	public static void main(String[] args) {

		// 前面放哪個飲料，後面放點餐後的細節
		Map<String, drinkDetail> myDrinkMap = new HashMap<String, drinkDetail>();
		// 假設1千個客人
		drink myDrink = null;
		drinkDetail myDrinkDetail = null;
		iceOrSugar myIceOrSugar = null;
		// myIceOrSugar.getIndex();

		int orderPeople = 1000;
		String[] detail = new String[orderPeople];
		
		for (int i = 0; i < orderPeople; i++) {
			myDrinkDetail = new drinkDetail();
			myDrinkDetail.setIce(myIceOrSugar.randomIceOrSugar());
			myDrinkDetail.setSugar(myIceOrSugar.randomIceOrSugar());
			myDrinkDetail.setNumber((int)(Math.random()*30+1));
			String drinkName = myDrink.randomDrink() +"_"+ i;
			myDrinkMap.put(drinkName, myDrinkDetail);
			detail[i] = drinkName+"-"+myDrinkDetail.getIce()+"-"+myDrinkDetail.getNumber()+"-"+myDrinkDetail.getSugar();
			//System.out.println(drinkName+"-"+myDrinkDetail.getIce()+"-"+myDrinkDetail.getNumber()+"-"+myDrinkDetail.getSugar());
		}
		
		//取出所有的Value
		Collection collection = myDrinkMap.values();
		//取出所有的Key
		Set keys = myDrinkMap.entrySet();
		Iterator iteratorKey = keys.iterator();
		Iterator iteratorValue = collection.iterator();
		while(iteratorKey.hasNext()) {
			Object key = iteratorKey.next();
			drinkDetail value = (drinkDetail)iteratorValue.next();

			/*
		    System.out.println(
		    		"飲料"+key+"-"+
		    		"糖量:"+value.getSugar()+
		    		",冰量:"+value.getIce()+
		    		",數量:"+value.getNumber());
		    */
			
		}
		
		for(int i = 0 ;i<orderPeople;i++){
			System.out.println(detail[i]);
		}
	}
}

class drinkDetail {
	private String ice;
	private String sugar;
	private int number;

	public String getIce() {
		return ice;
	}

	public void setIce(String ice) {
		this.ice = ice;
	}

	public String getSugar() {
		return sugar;
	}

	public void setSugar(String sugar) {
		this.sugar = sugar;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}
}